function GSChapter () {
	var WRAPPER_1_X = 30;
	var WRAPPER_1_Y = 30;
	var WRAPPER_2_X = 580;
	var WRAPPER_2_Y = 30;
	var WRAPPER_3_X = 30;
	var WRAPPER_3_Y = 370;
	var WRAPPER_4_X = 580;
	var WRAPPER_4_Y = 370;
	
	var WRAPPER_W = 520;
	var WRAPPER_H = 320;
	
	var SELECT_R = 63;
	var SELECT_G = 188;
	var SELECT_B = 255;
	var SELECT_ALPHA = 0.3;
	
	var BACKGROUND_BLUR_R = 0;
	var BACKGROUND_BLUR_G = 1;
	var BACKGROUND_BLUR_B = 2;
	var BACKGROUND_BLUR_ALPHA = 0.6;
	
	
	// Background image
	var splashImageHandle;
	var wrapperImageHandle;
	var lockImageHandle;
	var level1Handle;
	var level2Handle;
	var level3Handle;
	var level4Handle;
	
	// Profile
	var selecting = 0;
	var mouseStatus = 0;
	
	// Button
	var BACK_BUTTON_SXU = 0;
	var BACK_BUTTON_SYU = 0;
	var BACK_BUTTON_SXD = 0;
	var BACK_BUTTON_SYD = 150;
	var BACK_BUTTON_SW = 150;
	var BACK_BUTTON_SH = 150;
	
	var BACK_BUTTON_DX = 1125;
	var BACK_BUTTON_DY = 555;
	var BACK_BUTTON_DW = 150;
	var BACK_BUTTON_DH = 150;
	
	var backButton;
	
	this.Init = function () {
		splashImageHandle = g_graphicEngine.LoadImage("Data/MainMenu/MainBG.jpg");
		wrapperImageHandle = g_graphicEngine.LoadImage("Data/MainMenu/GSChapter/ChapterWrapper.png");
		lockImageHandle = g_graphicEngine.LoadImage("Data/MainMenu/GSChapter/Lock.png");
		
		level1Handle = g_graphicEngine.LoadImage("Data/MainMenu/GSLevel/Chapter 1.jpg");
		level2Handle = g_graphicEngine.LoadImage("Data/MainMenu/GSLevel/Chapter 2.jpg");
		level3Handle = g_graphicEngine.LoadImage("Data/MainMenu/GSLevel/Chapter 3.jpg");
		level4Handle = g_graphicEngine.LoadImage("Data/MainMenu/GSLevel/Chapter 4.jpg");
		
		backButton = new Button();
		backButton.LoadImage("Data/MainMenu/BackButton.png", BACK_BUTTON_SXU, BACK_BUTTON_SYU, BACK_BUTTON_SXD, BACK_BUTTON_SYD, BACK_BUTTON_SW, BACK_BUTTON_SH);
		backButton.SetPosition (BACK_BUTTON_DX, BACK_BUTTON_DY, BACK_BUTTON_DW, BACK_BUTTON_DH);
		backButton.RegisterFunction(BackToMainMenu);
	}
	
	this.Update = function () {
	
	}
	
	this.Draw = function () {
		g_graphicEngine.DrawFast (g_context, splashImageHandle, 0, 0);
		g_graphicEngine.FillCanvas (g_context, BACKGROUND_BLUR_R, BACKGROUND_BLUR_G, BACKGROUND_BLUR_B, BACKGROUND_BLUR_ALPHA, 0, 0, CANVAS_W, CANVAS_H);
		
		
		g_graphicEngine.Draw (g_context, level1Handle, 0, 0, CANVAS_W, CANVAS_H, WRAPPER_1_X, WRAPPER_1_Y, WRAPPER_W, WRAPPER_H);
		if (g_userProfile.m_chapter < 1) g_graphicEngine.DrawFast (g_context, lockImageHandle, WRAPPER_1_X, WRAPPER_1_Y);
		else {
			if (selecting == 1) g_graphicEngine.FillCanvas (g_context, SELECT_R, SELECT_G, SELECT_B, SELECT_ALPHA, WRAPPER_1_X, WRAPPER_1_Y, WRAPPER_W, WRAPPER_H);
		}
		g_graphicEngine.DrawFast (g_context, wrapperImageHandle, WRAPPER_1_X, WRAPPER_1_Y);
		
		
		
		
		g_graphicEngine.Draw (g_context, level2Handle, 0, 0, CANVAS_W, CANVAS_H, WRAPPER_2_X, WRAPPER_2_Y, WRAPPER_W, WRAPPER_H);
		if (g_userProfile.m_chapter < 2) g_graphicEngine.DrawFast (g_context, lockImageHandle, WRAPPER_2_X, WRAPPER_2_Y);
		else {
			if (selecting == 2) g_graphicEngine.FillCanvas (g_context, SELECT_R, SELECT_G, SELECT_B, SELECT_ALPHA, WRAPPER_2_X, WRAPPER_2_Y, WRAPPER_W, WRAPPER_H);
		}
		g_graphicEngine.DrawFast (g_context, wrapperImageHandle, WRAPPER_2_X, WRAPPER_2_Y);
		
		
		
		
		g_graphicEngine.Draw (g_context, level3Handle, 0, 0, CANVAS_W, CANVAS_H, WRAPPER_3_X, WRAPPER_3_Y, WRAPPER_W, WRAPPER_H);
		if (g_userProfile.m_chapter < 3) g_graphicEngine.DrawFast (g_context, lockImageHandle, WRAPPER_3_X, WRAPPER_3_Y);
		else {
			if (selecting == 3) g_graphicEngine.FillCanvas (g_context, SELECT_R, SELECT_G, SELECT_B, SELECT_ALPHA, WRAPPER_3_X, WRAPPER_3_Y, WRAPPER_W, WRAPPER_H);
		}
		g_graphicEngine.DrawFast (g_context, wrapperImageHandle, WRAPPER_3_X, WRAPPER_3_Y);
		
		
		
		
		g_graphicEngine.Draw (g_context, level4Handle, 0, 0, CANVAS_W, CANVAS_H, WRAPPER_4_X, WRAPPER_4_Y, WRAPPER_W, WRAPPER_H);
		if (g_userProfile.m_chapter < 4) g_graphicEngine.DrawFast (g_context, lockImageHandle, WRAPPER_4_X, WRAPPER_4_Y);
		else {
			if (selecting == 4) g_graphicEngine.FillCanvas (g_context, SELECT_R, SELECT_G, SELECT_B, SELECT_ALPHA, WRAPPER_4_X, WRAPPER_4_Y, WRAPPER_W, WRAPPER_H);
		}
		g_graphicEngine.DrawFast (g_context, wrapperImageHandle, WRAPPER_4_X, WRAPPER_4_Y);
		
		
		backButton.Draw();
	}
	
	
	this.OnSwitch = function () {
		
	}
	
	this.OnMouseMove = function (x, y) {
		if (mouseStatus == 1) {
			if (x >= WRAPPER_1_X && x <= WRAPPER_1_X + WRAPPER_W && y >= WRAPPER_1_Y && y <= WRAPPER_1_Y + WRAPPER_W) {
				selecting = 1;
			}
			else if (x >= WRAPPER_2_X && x <= WRAPPER_2_X + WRAPPER_W && y >= WRAPPER_2_Y && y <= WRAPPER_2_Y + WRAPPER_W) {
				selecting = 2;
			}
			else if (x >= WRAPPER_3_X && x <= WRAPPER_3_X + WRAPPER_W && y >= WRAPPER_3_Y && y <= WRAPPER_3_Y + WRAPPER_W) {
				selecting = 3;
			}
			else if (x >= WRAPPER_4_X && x <= WRAPPER_4_X + WRAPPER_W && y >= WRAPPER_4_Y && y <= WRAPPER_4_Y + WRAPPER_W) {
				selecting = 4;
			}
			else {
				selecting = 0;
			}
			
		}
		
		backButton.OnMouseMove (x, y);
	}
	
	this.OnMouseDown = function (x, y) {
		mouseStatus = 1;
		
		if (x >= WRAPPER_1_X && x <= WRAPPER_1_X + WRAPPER_W && y >= WRAPPER_1_Y && y <= WRAPPER_1_Y + WRAPPER_W) {
			selecting = 1;
		}
		else if (x >= WRAPPER_2_X && x <= WRAPPER_2_X + WRAPPER_W && y >= WRAPPER_2_Y && y <= WRAPPER_2_Y + WRAPPER_W) {
			selecting = 2;
		}
		else if (x >= WRAPPER_3_X && x <= WRAPPER_3_X + WRAPPER_W && y >= WRAPPER_3_Y && y <= WRAPPER_3_Y + WRAPPER_W) {
			selecting = 3;
		}
		else if (x >= WRAPPER_4_X && x <= WRAPPER_4_X + WRAPPER_W && y >= WRAPPER_4_Y && y <= WRAPPER_4_Y + WRAPPER_W) {
			selecting = 4;
		}
		else {
			selecting = 0;
		}
		
		backButton.OnMouseDown (x, y);
	}
	
	this.OnMouseUp = function (x, y) {
		if (selecting > 0) {
			SelectChapter(selecting);
			selecting = 0;
		}
		mouseStatus = 0;
		
		backButton.OnMouseUp (x, y);
	}
	
	this.OnMouseWheel = function (delta) {
	
	}
	
	this.OnKeyDown = function (keycode) {
	
	}
	
	this.OnKeyUp = function (keycode) {
	
	}
	
	var SelectChapter = function (chapter) {
		g_gsLevel.ChapterSelected (chapter);
		SwitchState (g_gsLevel, true);
	}
	
	var BackToMainMenu = function () {
		SwitchState (g_gsMainMenu, true);
	}
}
